<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$_SESSION['onemerchid']=0;
	$return['setting']=$return['pluginset'];
	$title=$return['pluginset']['share_title']?:$return['pluginset']['title'];
	$desc=$return['pluginset']['share_desc'];
	$logo=$return['pluginset']['share_image'];
	$return['member']=cfc('core')->get_member($_SESSION['uid']);
	$groupspram=array('uniacid'=>$_SESSION['uniacid'],'isrecommand'=>'1','isshow'=>'1','mid'=>0,'parentid'=>0);
	$groupspram['onepluginname']='';
	$groupspram['parentid']=intval($_RQ['id']);
	$category=pdo_getall('jy_weishop_goods_group',$groupspram,'','id','paixu desc');
	$return['category']=$category;
	//公告列表
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$notice_list = pdo_getslice('jy_weishop_notice',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array($pindex,20),$total,array('id','title','createtime'),'','id desc');
	if($notice_list){
		foreach($notice_list as &$notice){
			if($_SESSION['os']=='windows'){
				$notice['createtime']=date('m-d',$notice['createtime']);
			}else{
				$notice['createtime']=date('Y-m-d h:i',$notice['createtime']);
			}
		}
	}
	$return['notice_list']=$notice_list;
	//推荐商品
	$parameter=array(
		'params'=>array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'saletype likes'=>array('1')),
		'fields'=>array('id','title','image','price','total','active_plugin','active_id','salenum','pluginname'),
		'limit'=>6,
	);
	if(cfc('core')->plugin_exists('jy_weishop')){
		$isjy_weishop=true;
		$goods=model('jy_weishop/goods')->goods_list($parameter);
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	if($_RQ['groupid']){
		$params['groupid']=intval($_RQ['groupid']);
		$return['params']['groupid']=intval($_RQ['groupid']);
	}
    $orderby='id desc';
	$total='';
	if($isjy_weishop){
		$videos=pdo_getslice('jy_weishop_video',$params,array($pindex,$psize),$total,'','',$orderby);
		foreach($videos as &$itemv){
			$itemv['images']=json_decode($itemv['images'],true);
			$pindex = max(1, 0);
			$members=pdo_getslice('jy_weishop_video_looklist',array('uniacid'=>$_SESSION['uniacid'],'oid'=>$itemv['id']),array($pindex,5),$total,array('mid'),'','id desc');
			foreach($members as &$mv){
				$memberinfo=pdo_get('core_members',array('id'=>$mv['mid']),array('nickname','avatar'));
				$mv['nickname']=$memberinfo['nickname'];
				$mv['avatar']=$memberinfo['avatar'];
			}
			$itemv['members']=$members;
			$itemv['likes']=pdo_count('jy_weishop_video_like',array('uniacid'=>$_SESSION['uniacid'],'oid'=>$itemv['id']),'id');
		}
	}
	$return['goods']=$goods;
	$return['videos']=$videos;
	$sharelink='jy_ad/index//fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
			'title'=>$title?:'新闻中心',
			'desc'=>$desc?:'新闻中心！最新公司活动动态！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>tomedia($logo),
	);
	$return['list']=array();
	$return['pcd']=array();
	$return['params']['pid']=intval($_RQ['pid']);
	$return['time']=time();
    $return['adwei']=1;
    $return['placement_id']=$this->model('model')->get_placement_id(1);
	set_html('title',$title);
	exi($return);
}
if($_RQ['op']=='upad_log'){
    $post=get_postdata();
    if($post['adwei']){
        $this->model('model')->add_log($post['adwei']);
    }
    exi('更新成功！');
}
?>